/* ==============================================================================
 * 创 建 者：lyt
 * 创建日期：2017-07-14	
 * 功能描述：

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//会员图谱（接点图谱）
var getRecommendChartUrl = baseUrl + 'MemberF/GetConnectTreeData';
//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';

var vu;
var ztree;
var setting;
$(function(){
	initVue();
	LoadZtree('', true);
});

function initVue(){
	vu = new Vue({
		el : '#mescroll',
		data : { 
			member : '',
			pageIndex : 1,
			TotalPageCount : '',
			html : '',
		},
		mounted: function() {
//			this.getList();
			this.getMemberView();
		},
		methods : {
			getMemberView : getMemberView,
			getRecommendChart : getRecommendChart,
			
		}
	})
}

function getRecommendChart(){
	common.get(getRecommendChartUrl + '?name=' + (vu.name || "") + '&level=' + vu.level, {},"", function (r) {
        vu.html = '';
        $("#tree").remove();
        $("#org").remove();
        if (r.ErrorCode == 0) {
            if (r.Data.html) {
                $("#tree").remove();
                vu.html = r.Data.html;
                $("#tree").html(vu.html);
            }
        } else {
            mui.toast(r.ErrorMsg, 'error');
        }
    })
}

function filter(treeId, parentNode, responseDataHtml) {
    var responseData = responseDataHtml.Data.html;
    if (!responseData) return null;
    for (var i = 0, l = responseData.length; i < l; i++) {
        responseData[i].name = responseData[i].name.replace(/\.n/g, '.');
    }
    return responseData;
}

function GetSetting(smid, isInit) {
     setting = {
        view: {
            dblClickExpand: false,
            showLine: true,
            nameIsHTML: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        async: {
            enable: true,
            url: getRecommendChartUrl,
            autoParam: ["id"],
            dataType: "json",
            type: "post",
            cache: false,
            otherParam: ["serachId", smid],
            dataFilter: filter
        },
        callback: {
			onClick: onClick
		}
    };
    return setting;
}

function LoadZtree(smid, isInit) {
    $("#tree").html("");
    $.fn.zTree.init($("#tree"), GetSetting(smid, isInit));
}

function onClick(e,treeId, treeNode) {
	zTree = $.fn.zTree.getZTreeObj("tree");
	zTree.expandNode(treeNode);
}


function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}


